package com.sky.mapper;

import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import com.sky.vo.OrderReportVO;
import com.sky.vo.UserReportVO;
//import jdk.vm.ci.meta.Local;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Mapper
public interface ReportMapper {

//
//    /**
//     * 数据统计
//     * @param begin
//     * @param end
//     * @return
//     */
//    @Select("select * from orders where order_time >= #{begin} and order_time <= #{end} and status = 5")
//    List<Orders> getByTime(String begin, String end);
    // 视频方法 : 用动态sql可扩展性强
    Double findByTime(Map map);
    

    /**
     * 用户统计
     * @param begin
     * @param end
     * @return
     */
    @Select("select count(user_id) as total_user_list ,count(distinct user_id) as new_user_list,date(order_time) as date_list from orders  where order_time between #{begin} and #{end} group by date(order_time)")
    List<UserReportVO> getUserStatistics(String begin, String end);


//    /**
//     * 有效订单统计
//     * @param begin
//     * @param end
//     * @return
//     */
//
//    @Select("SELECT   \n" +
//            "    DATE(order_time) AS date_list,   \n" +
//            "    COUNT(*) AS order_count_list,   \n" +
//            "    COUNT(CASE WHEN status = 5 THEN 1 END) AS valid_order_count_list \n" +
//            "FROM   \n" +
//            "    orders  \n" +
//            "WHERE   \n" +
//            "    order_time BETWEEN #{begin} AND #{end}  \n" +
//            "GROUP BY   \n" +
//            "    DATE(order_time)  \n" +
//            "ORDER BY   \n" +
//            "    date_list")
//    List<OrderReportVO> getOrdersStatistics(String begin, String end);



    Integer findByMap(Map map);

    List<UserReportVO> getUserStatisticsPlus(String begin, String end);
}
